{% extends 'sys_manage.html' %}
{% block table %}
    {#    {% if cate == '0' %}#}
    <div class="layui-row">
        <div class="layui-col-md6">·
            <span>状态：</span>
            <span class="layui-breadcrumb" lay-separator="|" id="status">
                  <a href="/user/resource/application/0/" status="0">待审核</a>
                  <a href="/user/resource/application/1/" status="1">已通过</a>
                  <a href="/user/resource/application/2/" status="2">被拒绝</a>
                </span>
        </div>
    </div>
{#    {% if request.session.level_id == 0 and all_r == '1' %}#}
        {#        超级管理员看到的资源交互记录#}
{#        <table class="layui-table"#}
{#               lay-data="{url:'/user/resource/application/3/?status={{ cate }}&all_r={{ all_r }}',text:{none:'当前暂无信息'},limit: 10, page:true, id:'apply_table'}"#}
{#               lay-filter="application">#}
{#            <thead>#}
{#            <tr>#}
{#                <th lay-data="{field: 'id',  width: 70, sort: true, fixed: true}">序号</th>#}
{#                <th lay-data="{field: 'resource_name',  width: 180}">资源名称</th>#}
{#                <th lay-data="{field: 'apply_user_name',  width: 90}">申请者</th>#}
{#                <th lay-data="{field: 'dir',  width: 130}">资源所属目录</th>#}
{#                <th lay-data="{field: 'root_dir', width: 130}">资源所属部门</th>#}
{#                <th lay-data="{field: 'resource_user_name', width: 100}">审核者</th>#}
{#                <th lay-data="{field: 'apply_time', width: 160}">申请时间</th>#}
{#                <th lay-data="{field: 'status', width: 80, templet: '#status_num'}">状态</th>#}
                {#                                <th lay-data="{fixed: 'right',  width: 100, align: 'center', toolbar: '#operate_bar'}">操作</th>#}
{#            </tr>#}
{#            </thead>#}
{#        </table>#}
{#    {% else %}#}
        <table class="layui-table"
               lay-data="{url:'/user/resource/application/3/?status={{ cate }}',text:{none:'当前暂无信息'},limit: 10, page:true, id:'apply_table'}"
               lay-filter="application">
            <thead>
            <tr>
                <th lay-data="{field: 'id',  width: 80, sort: true, fixed: true}">序号</th>
                <th lay-data="{field: 'resource_name',  width: 180}">资源名称</th>
                <th lay-data="{field: 'dir',  width: 160}">资源所属目录</th>
                <th lay-data="{field: 'root_dir', width: 141}">资源所属部门</th>
                <th lay-data="{field: 'apply_time', width: 180}">申请时间</th>
                <th lay-data="{field: 'status', width: 100,templet: '#status_num'}">状态</th>
                <th lay-data="{fixed: 'right',  width: 100, align: 'center', toolbar: '#operate_bar'}">操作</th>
            </tr>
            </thead>
        </table>
{#    {% endif %}#}
    <script type="text/html" id="status_num">
        {% verbatim %}
        {{#  if(d.isdelete == 1){ }}
            <span>资源已删除</span>
        {{#  } else { }}
            {{#  if(d.status == 1){ }}
            <i class="layui-icon" style="color: green" title="通过">&#xe617;</i>
            {{#  } else if(d.status == 2) { }}
            <i class="layui-icon" style="color: red" title="拒绝">&#xe617;</i>
            {{#  } else if(d.status == 0) { }}
            <i class="layui-icon" style="color: grey" title="待审核">&#xe617;</i>
            {{#  } }}
        {{#  } }}

        {% endverbatim %}
    </script>
    <script type="text/html" id="operate_bar">
        {% if cate == '0' %}
            <span class="layui-btn-xs layui-btn layui-btn-disabled">待审核</span>
{#            <a class="layui-btn layui-btn-danger layui-btn-xs" data-type="auto"#}
{#               lay-event="del">撤回申请</a>#}
        {% elif cate == '1' %}
            <a class="layui-btn layui-btn-xs" lay-event="resource_detail">查看详情</a>
        {% elif cate == '2' %}
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="refuse_reason">查看原因</a>
        {% endif %}
    </script>
{% endblock %}

{% block customjs %}
    {{ block.super }}
    <script>
        $(function () {
            $('#apply').addClass('layui-this');
            $('#status a[status="{{ cate }}"]').addClass('status-this');
{#            {% if all_r == '1' %}#}
{#            $('#apply_all').parent().addClass('layui-nav-itemed');#}
{#            $('#apply_all a[status="{{ cate }}"]').addClass('layui-this').css({color: '#fff'});#}
{#            {% elif all_r == '0' %}#}
{#            $('#apply').parent().addClass('layui-nav-itemed');#}
{#            $('#apply a[status="{{ cate }}"]').addClass('layui-this').css({color: '#fff'});#}
{#            {% endif %}#}
        });
        layui.use(['table'], function () {
            var table = layui.table;
            var layer = layui.layer;
            //监听操作选项的工具条事件
            table.on('tool(application)', function (obj) {
                var data = obj.data;
                if (obj.event === 'refuse_reason') {
                    // 向服务端发送获取原因的请求
                    $.ajax({
                            type: 'get',
                            url: '/user/resource/?real_id=' + data.real_id,
                            dataType: 'json',
                            success: function (data) {
                                if (data.code === 0) {
                                    layer.alert(data.msg);
                                } else {
                                    layer.alert(data.msg)
                                }
                            }
                        }
                    )
                } else if (obj.event === 'del') {
                    layer.confirm('真的要撤回申请么？', function (index) {
                        //向服务端发送删除指令
                        $.ajax({
                                type: 'delete',
                                url: '/user/resource/',
                                data: {real_id: data.real_id},
                                dataType: 'json',
                                success: function (data) {
                                    if (data.code === 0) {
                                        layer.msg(data.msg, {
                                            icon: 6, time: 2000, end: function () {
                                                {#                                                obj.del(); //删除对应行（tr）的DOM结构，并更新缓存#}
                                                {#                                                layer.close(index);#}
                                                location.reload()
                                            }
                                        });
                                    } else {
                                        layer.alert(data.msg)
                                    }
                                }
                            }
                        )
                    });
                } else if (obj.event === 'resource_detail') {
                    // 跳转至资源详情页面
                    var resource_id = data.resource_id;
                    window.open('/resource/desc/' + resource_id + '.html/')
                }
            });
        })
        ;
    </script>
{% endblock %}